package com.showtao.front.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.showtao.common.security.domain.Permission;
import com.showtao.common.security.domain.Role;

@SuppressWarnings("serial")
public class RoleDto implements Serializable {

    private String roleName;
    private String description;
    private Date createdAt;
    private Date updatedAt;
    private List<String> permissions;

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public List<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<String> permissions) {
        this.permissions = permissions;
    }
    
    public static RoleDto from(Role role){
        RoleDto dto = new RoleDto();
        dto.setRoleName(role.getRoleName());
        dto.setDescription(role.getDescription());
        dto.setCreatedAt(role.getCreatedAt());
        dto.setUpdatedAt(role.getUpdatedAt());
        if(role.getPermissions()!=null){
            dto.setPermissions(new ArrayList<String>());
            for(Permission p : role.getPermissions()){
                dto.getPermissions().add(p.getPermission());
            }
        }
        return dto;
    }
}
